<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增中台配置公共服务')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-centrePublicConfig-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">系统名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">网络地址：</label>
                <div class="col-sm-8">
                    <input name="webUrl" class="form-control" type="text" maxlength="100" required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">logo页图片地址：</label>
                <div class="col-sm-8">
                    <input name="logo" id="logo" class="form-control" type="hidden" required>
                    <div class="layui-upload">
                        <button type="button" class="layui-btn" id="test2">上传图片</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="demo2" style="width: 100%;">
                            <p id="demoText2"></p>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">排序值：</label>
                <div class="col-sm-8">
                    <input name="sortValue" class="form-control" type="number" maxlength="5">
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "centre/centrePublicConfig"
        $("#form-centrePublicConfig-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-centrePublicConfig-add').serialize());
            }
        }

        layui.use('upload', function(){
            var $ = layui.jquery
                ,upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test2'
                ,url: ctx + "common/upload" //改成您自己的上传接口
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){

                        $('#demo2').attr('src', result); //图片链接（base64）
                    });
                }
                ,done: function(res){
                    //如果上传失败
                    if(res.code > 0){
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $('#logo').val(res.fileName); //图片路径
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText2');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
        });

    </script>
</body>
</html>